#!/bin/sh

BASEDIR="`dirname "${0}"`/.."
. "${BASEDIR}/functions"

NTRIES=6

for tc in "0 3 4 8 9" "18 3 4 9 0"
do
  i=0
  testok=0
  fcmd="${BASEDIR}/forwarding/forwarding1"
  while [ ${i} -lt ${NTRIES} ]
  do
    echo -n "Running ${fcmd}, codecs ${tc}: try ${i} of ${NTRIES}..."
    if env TEST_CODECS="${tc}" ${fcmd} > forwarding1_robust.rout 2>&1
    then
      testok=1
      echo " success"
      break
    fi
    echo " failure"
    if [ ${i} -eq 0 ]
    then
      fcmd="env GCOV_PREFIX=/tmp ${fcmd}"
    fi
    i=$((${i} + 1))
  done
  cat forwarding1_robust.rout
  if [ ${testok} -eq 0 ]
  then
    forcefail 1 "forwarding1 (codecs ${tc}) has failed after ${NTRIES}"
  fi
done
